package com.sktlab.bizconfmobile.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.content.Context;

import com.sktlab.bizconfmobile.R;

public class ValidatorUtil {
	
	public static boolean verifyPhoneNumber(Context ctx, String phoneNum) {
		
		boolean result = false;
		
		do{
			if(phoneNum == null || phoneNum.equalsIgnoreCase("")){
				
				Util.shortToast(ctx, R.string.toast_phone_num_null);
				break;
			}
			
			if(!ValidatorUtil.isPhoneNumberValid(phoneNum)){
				
				Util.shortToast(ctx, R.string.toast_phone_num_invalid);
				break;
			}
			
			result = true;
			
		}while(false);
		
		return result;
	}
	
	public static boolean isPhoneNumberValid(String paramString) {
		
		  boolean isValid = false;
		   /*
		    * accept phone format
		    */
		   String expression = "^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{5})$";
		   String expression2 = "^\\(?(\\d{3})\\)?[- ]?(\\d{4})[- ]?(\\d{4})$";
		  
		   Pattern pattern = Pattern.compile(expression);
		   Matcher matcher = pattern.matcher(paramString);
		   
		   Pattern pattern2 = Pattern.compile(expression2);
		   Matcher matcher2 = pattern2.matcher(paramString);
		   if(matcher.matches() || matcher2.matches()) {
			   isValid = true;
		   }
		   return isValid;
	}

	
	public boolean isEmailValid(String paramString) {
		Matcher matcher;
		Pattern pattern = Pattern
				.compile("(?i)^[\\p{L}0-9._%+-\\\\']+@[\\p{L}0-9._%+-\\\\']+\\.[\\p{L}]{2,}$");

		matcher = pattern.matcher(paramString);
		return matcher.matches();
	}
}
